var e = require("../@babel/runtime/helpers/toConsumableArray");

function t(e) {
    return e < 10 ? "0" + e : "" + e;
}

function a(e, a) {
    a = a || 1;
    for (var r = [], n = e = e || 0; n <= a; n++) r.push(t(n));
    return r;
}

function r(e, t) {
    var r = e % 400 == 0 || e % 4 == 0 && e % 100 != 0, n = null;
    switch (t) {
      case "01":
      case "03":
      case "05":
      case "07":
      case "08":
      case "10":
      case "12":
        n = a(1, 31);
        break;

      case "04":
      case "06":
      case "09":
      case "11":
        n = a(1, 30);
        break;

      case "02":
        n = a(1, r ? 29 : 28);
        break;

      default:
        n = "月份格式不正确，请重新输入！";
    }
    return n;
}

module.exports = {
    dateTimePicker: function(n, s, c) {
        var u, i = [], o = [ [], [], [], [], [], [] ], l = n || 1978, g = s || 2100, p = c ? [].concat(e(c.split(" ")[0].split("-")), e(c.split(" ")[1].split(":"))) : [ t((u = new Date()).getFullYear()), t(u.getMonth() + 1), t(u.getDate()), t(u.getHours()), t(u.getMinutes()), t(u.getSeconds()) ];
        return o[0] = a(l, g), o[1] = a(1, 12), o[2] = r(p[0], p[1]), o[3] = a(0, 23), o[4] = a(0, 59), 
        o[5] = a(0, 59), o.forEach(function(e, t) {
            i.push(e.indexOf(p[t]));
        }), {
            dateTimeArray: o,
            dateTime: i
        };
    },
    getMonthDay: r,
    timeHandle: function(e) {
        var t = e / 1e3, a = new Date(1e3 * t), r = a.getFullYear(), n = a.getMonth() + 1, s = a.getDate(), c = a.getHours(), u = a.getMinutes(), i = a.getSeconds();
        n < 10 && (n = "0" + n), s < 10 && (s = "0" + s), c < 10 && (c = "0" + c), u < 10 && (u = "0" + u), 
        i < 10 && (i = "0" + i);
        var o = new Date().getTime() / 1e3 - t, l = parseInt(o / 86400), g = parseInt(o / 3600), p = parseInt(o / 60), d = parseInt(o);
        return l > 0 && l < 3 ? l + "天前" : l <= 0 && g > 0 ? g + "小时前" : g <= 0 && p > 0 ? p + "分钟前" : d < 60 ? d <= 0 ? "刚刚" : d + "秒前" : l >= 3 && l < 30 ? n + "-" + s + " " + c + ":" + u : l >= 30 ? r + "-" + n + "-" + s + " " + c + ":" + u : void 0;
    }
};